package com.lam.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.dormitory.entity.Permission;
import com.lam.dormitory.entity.Role;
import com.lam.dormitory.mapper.PermissionMapper;
import com.lam.dormitory.service.IPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lam
 * @since 2019-12-20
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {

    @Override
    public List<Permission> selectMenuByUserId(Long userId) {
        return this.baseMapper.selectMenuByUserId(userId);
    }

    @Override
    public List<Permission> selectPermissionByRoleId(Long roleId) {
        return this.baseMapper.selectPermissionByRoleId(roleId);
    }

    @Override
    public Permission selectPermissionByName(String name) {
        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Permission::getName, name);
        return this.baseMapper.selectOne(wrapper);
    }


    @Override
    public List<Permission> selectByPermission(Permission permission) {
        return this.baseMapper.selectByPermission(permission);
    }

    @Override
    public List<Permission> selectAllMenuName() {
        return this.baseMapper.selectAllMenuName();
    }

    @Override
    public int selectSubPermsByPermissionId(Long permissionId) {
        return this.baseMapper.selectSubPermsByPermissionId(permissionId);
    }

    @Override
    public List<Permission> selectPermsAndChildren(Long permissionId) {
        return this.baseMapper.selectPermsAndChildren(permissionId);
    }
}
